//跳转到驾驶员信息页面
var godrvAnaDriverInfo;
//跳转到线路信息页面
var goLineInfo;
//跳转到车辆信息页面
var goCarInfo;
require(['grid', 'topBar', 'layout','date'], function () {
    var $top = $('#top'),$grid = $('#grid'),reloadGridData,postData;
	
    //顶部栏初始化
    function topBarInit() {
        $top.topBar({
            left: [
               	{type: 'filter-more',
           	     dateType:'custom',
	            	search: function () {
	        		reloadGridData();
                },
                item: [
                       {
                           text: '时间快捷',
                           name1: 'beginTime',
                           name2: 'endTime',
                           type: 'dateLine'
                       }, {
                           text: '类别',
                           name: 'setType',
                           type: 'item-select',
                           dict: 'STNB0000',
                           data:[
                               {text: '全部', value: ''}
                           ]
                       }
                   ]
        		}
            ],
            right: [
                {
                    text: '导出',
                    type: 'export-btn',
                    authority: '',
                    item: [
                        {
                            text: 'Excel导出',
                            click: function () {
                            	exportFile('Excel');
                            }
                        },
                        {
                            text: 'PDF导出',
                            click: function () {
                            	exportFile('Pdf');
                            }
                        }
                    ]
                }
            ]
        });
    }

    //grid初始化
    function gridInit() {
        $grid.grid({
            url: "/operationReport/searchStationBehaviorMonitor.htm",
            colModel: [
				{name: "id",label: 'id',key: true, hidden: true},
				{name: "carId", label: "carId", hidden: true},
                {name: "lineId", label: "lineId", hidden: true},
                {name: "drvId", label: 'drvId', hidden: true},
				{name: "drvName",label: '驾驶员',width: 80,align: "left",formatter: 'customCurrency',formatoptions:{
	                redbtn:true,
	                css:'text-link c-blue',
	                clickFn:function(rowObject,cellvalue){
	                	godrvAnaDriverInfo(rowObject.drvId);
	                }
	            }},
				{name: "licPltNo",label: '车牌号',width: 80,align: "left",formatter: function (cellvalue,options,rowObject) {
                	return "<b><a href='javascript:void(0);' onclick='goCarInfo(\"" + rowObject.carId + "\")' class='text-link c-blue'>" + cellvalue + "</a></b>";
                }},
				{name: "carInCd", label: "车辆编号", width: 80},
				{name: "lineName",label: '运营线路',width: 80,align: "left",formatter: 'customCurrency',formatoptions:{
	                redbtn:true,
	                css:'text-link c-blue',
	                clickFn:function(rowObject,cellvalue){
	                	goLineInfo(rowObject.lineId);
	                }
	            }},
				{name: "organName",label: '所属机构',width: 185,align: "left"},
				{name: "rcrdTime",label: '发生时间',width: 150,align: "center"},
				{name: "lineType",label: '方向',dict: "LIT00000",width: 60,align: "left"},
				{name: "stnName",label: '站点',width:135,align: "left"},
				{name: "cgy",label: '类别',dict: "STNB0000",width: 60,align: "left"},
				{name: "getinTime",label: '进站时间',width:160,align: "center"},
				{name: "getoutTime",label: '出站时间',width:160,align: "center"},
				{name: "wthrSpdOfMotVhi",label: '车速是否为0',width: 85,align: "right"},
				{name: "wthrCar",label: '车门是否打开',width: 85,align: "right"},
				{name: "dura",label: '时长(s)',width: 60,align: "right"},
				{name: "paramSetValue",label: '参数值(s)',width: 60,align: "right"}
            ],
            multiselect: false
        });
    }
    
    //获取左侧选择的节点信息
    function getPostData() {
        var rcx = commonFun.getTreeCheckNodeToArgs();
        var type = commonFun.getLeftTreeCurrentTreeType();
        var orgIds = commonFun.getLeftTreeCheckedNodes(type);
        if (rcx) {
            postData = $.extend(rcx, $("#top").parent().getValues());
        	postData.type = type;
            postData.orgIds = orgIds;
        }
        return rcx;
    }
    
    //查询grid
	reloadGridData = function(){
		if (getPostData()) {
			 $grid.grid('setGridParam', {
	             datatype: "JSON",
	             page: 1,
	             postData: postData
	         }).trigger("reloadGrid");
		 }
	};
	
	//导出
	function exportFile(suffix){
		if($grid.getGridParam("reccount")>0){
            if(getPostData()) {
    		    $.exportFile("/operationReport/exportStationBehaviorMonitor"+suffix+".htm",postData);
	        };
		}
		else{
			$.messager.alert("警告","请先查询数据！","info");
		};
    }
	
	 //跳转到驾驶员信息页面
    godrvAnaDriverInfo = function(drvId){
    	var data = {};
    	data.drvId = drvId;
    	$.openTab('8252b8b5e5ff49c08b02f6865562b506','showDrvInfo',[data]);
    };
    //跳转到车辆信息页面
    goCarInfo = function(carId){
    	var data = {};
    	data.carId = carId;
    	$.openTab('6bad880fef164ec6adaea7b18420eb6e','showCarInfo',[data]);
    }
    //跳转到线路信息页面
    goLineInfo = function(lineId){
    	var data = {};
    	data.lineId = lineId;
    	$.openTab('4db17f8a322b4749a61eb2f8a12023ae','showLineInfo',[data]);
    }
	 
    //layout 布局
    $('body').layout();

    topBarInit();
    gridInit();
    
});